#include "PiecesModelling.h"

#include "PiecesTextures.h"
#include "../frameworks/Drawer.h"

float obsidian_shininess[] = {128.0};
float obsidian_ambient[] =  {0.05375, 0.05, 0.06625, 1.0};
float obsidian_diffuse[] =  {1.0, 1.0, 1.0, 1.0};
float obsidian_specular[] = {0.332741, 0.328634, 0.346435, 1.0};

float pearl_shininess[] = {128.0};
float pearl_ambient[] =  {0.25, 0.20725, 0.20725, 1.0};
float pearl_diffuse[] =  {1.0, 0.829, 0.829, 1.0};
float pearl_specular[] = {0.296648, 0.296648, 0.296648, 1.0};

float silver_shininess[] = {64.0};
float silver_ambient[] =  {0.19225, 0.19225, 0.19225, 1.0};
float silver_diffuse[] =  {1.0, 1.0, 1.0, 1.0};
float silver_specular[] = {0.508273, 0.508273, 0.508273, 1.0};

void draw_soldier(GLUquadric *glQ, int tex_id) {

	double clipEquation[4] = {0, Y_NORMAL, 0, 0};
	glPushMatrix();

		glDisable(GL_COLOR_MATERIAL);

		glEnable(GL_NORMALIZE);

		glMaterialfv(GL_FRONT_AND_BACK, GL_SHININESS, silver_shininess);
		glMaterialfv(GL_FRONT_AND_BACK, GL_SPECULAR,  silver_specular);
		glMaterialfv(GL_FRONT_AND_BACK, GL_DIFFUSE,   silver_diffuse);
		glMaterialfv(GL_FRONT_AND_BACK, GL_AMBIENT,   silver_ambient);
		

		glEnable(GL_TEXTURE_2D);
		gluQuadricTexture(glQ, GL_TRUE);
		gluQuadricDrawStyle(glQ, GLU_FILL);
	    glBindTexture(GL_TEXTURE_2D, tex_id);
		
		glTranslatef(DUMMY_SQUARE_DIM / 2.0, 0.0, DUMMY_SQUARE_DIM / 2.0);
		glScaled(DUMMY_SQUARE_DIM - DUMMY_SQUARE_DIM/4, 2, DUMMY_SQUARE_DIM - DUMMY_SQUARE_DIM/4);

		glEnable(GL_CLIP_PLANE0);
		   glClipPlane(GL_CLIP_PLANE0, clipEquation);
		   glPushMatrix();
		       glRotated(-180, 1, 0, 0);
			   gluSphere(glQ, SOLDIER_SPHERE_RADIUS, SOLDIER_SPHERE_SUBDIVISIONS, SOLDIER_SPHERE_SUBDIVISIONS);
		   glPopMatrix();
		glDisable(GL_CLIP_PLANE0);

		
		glPushMatrix();
			glRotated(90, 1, 0, 0);
			gluDisk(glQ, 0, SOLDIER_SPHERE_RADIUS , SOLDIER_SPHERE_SUBDIVISIONS , SOLDIER_SPHERE_SUBDIVISIONS );
		glPopMatrix();
		
		glDisable(GL_TEXTURE_2D);

		glDisable(GL_NORMALIZE);

		glEnable(GL_COLOR_MATERIAL);

	glPopMatrix();
}

void draw_house(int texs[]) {
	glPushMatrix();
	
	glDisable(GL_COLOR_MATERIAL);

		glEnable(GL_NORMALIZE);

		glMaterialfv(GL_FRONT_AND_BACK, GL_SHININESS, silver_shininess);
		glMaterialfv(GL_FRONT_AND_BACK, GL_SPECULAR,  silver_specular);
		glMaterialfv(GL_FRONT_AND_BACK, GL_DIFFUSE,   silver_diffuse);
		glMaterialfv(GL_FRONT_AND_BACK, GL_AMBIENT,   silver_ambient);

		glPushMatrix();
			glTranslatef(DUMMY_SQUARE_DIM / 2.0, HOUSE_DIM_Y / 2.0, DUMMY_SQUARE_DIM / 2.0);
			glScalef( HOUSE_DIM_XZ , HOUSE_DIM_Y , HOUSE_DIM_XZ);
			draw_cube(texs, 0);
		glPopMatrix();


		glDisable(GL_NORMALIZE);
	glEnable(GL_COLOR_MATERIAL);

	glPopMatrix();
}